<?php
require_once('config.param.php');
class Param_regionController extends Gaf_Controller_Action {
	
	private $rm;
	public function init(){
		parent::init();
		$this->rm=new region();
	}
	/**
	 * @name 参数设置
	 * @menu 参数设置/地区参数
	 * @comment 地区参数管理，设置地区参数。
	 * @type WEB
	 */
	public function indexAction(){
		$p=$this->_getParam("p","0");
		$this->view->MsgSection=$this->_getParam('errmsg');
		
		$reglist=$this->rm->getRegionList();
		$this->view->reglist=$reglist;
		$this->view->page=$p;
	}
	public function addregionAction(){
		$rname=$this->_getParam('rname');
		$level=$this->_getParam('level');
		if($rname!=''&&$rname!=null){
			//$rm=new region();
			$this->rm->addRegion($rname,$level);
			$this->_redirect("/param/region/index?errmsg=添加成功");
		}
	}
	public function editregionAction(){
		$rid=$this->_getParam('rid');
		//$rm=new region();
		$region=$this->rm->getRegionByid($rid);
		$this->view->region=$region;
	}
	public function doeditregAction(){
		$rname=$this->_getParam('rname');
		$rid=$this->_getParam('rid');
		$rlevel=$this->_getParam('level');
		$ret=$this->rm->updateRegion($rid,$rname,$rlevel);
		if($ret)	$this->_redirect("/param/region/index?errmsg=修改成功");
		else $this->_redirect("/param/region/index?errmsg=修改失败");
	}
	public function delregionAction(){
		$this->_helper->viewRenderer->setNoRender();
		$rid=$this->_getParam('rid');
		//$rm=new region();
		$ret=$this->rm->delRegion($rid);
		if($ret)	$this->_redirect("/param/region/index?errmsg=删除成功");
		else $this->_redirect("/param/region/index?errmsg=删除失败");
	}
}